package com.qfmy.app.controller.community;

import com.qfmy.app.service.community.BlogService;
import com.qfmy.app.vo.community.BlogVo;
import com.qfmy.common.result.Result;
import com.qfmy.model.entity.query.BlogQuery;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.app.controller.community
 * @date 2025/4/17
 * @description 博客
 */
@RestController
@SuppressWarnings("all")
@RequestMapping("/app/blog")
public class BlogController {

    /**
     * 注入service
     */
    @Resource
    private BlogService blogService;

    /**
     * 新增博客
     */
    @RequestMapping("/addBlog")
    public Result addBlog(@RequestBody BlogQuery blogQuery) {
        blogService.addBlog(blogQuery);
        return Result.ok();
    }

    /**
     * 分页获取文章
     */
    @RequestMapping("/getBlogList")
    public Result getBlogList(@RequestParam Integer pageNum, @RequestParam Integer size) {
        List<BlogVo> blogList = blogService.getBlogList(pageNum, size);
        return Result.ok(blogList);
    }

    /**
     * 更新阅读量
     */
    @RequestMapping("/updateReadCount")
    public Result updateReadCount(@RequestParam Long id) {
        blogService.updateReadCount(id);
        return Result.ok();
    }
}
